#include "StdAfx.h"
#include "TPTexture.h"

extern PTP_SetReadFileInterface g_SupportFile;
CTPTexture::CTPTexture(void)
{
}

CTPTexture::~CTPTexture(void)
{
}

BOOL CTPTexture::FillColor( LPVOID pColorData, BYTE* & pBuffer, int nWidth, int nHeight, eBufferFormat eFormat )
{
	return FillInCMethod(pColorData,pBuffer,nWidth,nHeight,eFormat);
}

int CTPTexture::SaveColorToBuffer( LPVOID pColorDef, LPVOID lpBuffer, int nLength )
{
	return 0;
}

int CTPTexture::LoadColorFromBuffer( LPVOID hColor,LPVOID lpBuffer,int nLength )
{
	return 0;
}

BOOL CTPTexture::FillInCMethod( LPVOID pColorData, BYTE* & pBuffer, int nWidth, int nHeight, eBufferFormat eFormat )
{
	TPTexture* pColorInfo = (TPTexture*)pColorData;
	eLayOutType eLayType =  pColorInfo->eLayType;
	TCHAR*	pFileName = pColorInfo->pFileName;

	DWORD* pImage = NULL;
	int nImageWidth = 0;
	int nImageHeight = 0;

	if(g_SupportFile && g_SupportFile(pImage,nImageWidth,nImageHeight,pFileName))
	{
		DWORD* pTempBuff = new DWORD[nWidth * nHeight];

		switch(eLayType)
		{
		case eStretch:
			FillColorStretch(pTempBuff,nWidth,nHeight,pImage,nImageWidth,nImageHeight);
			break;
		case eLayMiddle:
			FillColorMid(pTempBuff,nWidth,nHeight,pImage,nImageWidth,nImageHeight);
			break;
		case ePadding:
			FillColorPadding(pTempBuff,nWidth,nHeight,pImage,nImageWidth,nImageHeight);
			break;
		}
		delete[] pImage;
		BufferToByte(pTempBuff,pBuffer,nWidth,nHeight);
		delete[] pTempBuff;
		return TRUE;
	}
	return FALSE;
}
